<?php


class Blackbird_Form_Users_SignUp extends Zend_Form
{
	function __construct($options = null)
	{
		parent::__construct($options);

		$translateCountries = new Zend_Config(require LIBRARY_PATH . '/Blackbird/language/es/countries.php');
		$countryOptions = $translateCountries->toArray();

		$genderOptions = array(
			'F' => ' Femenino',
			'M' => ' Masculino',
		);

		$this
			->addElement('text', 'email', array(
				'class' => 'important',
				'description' => 'Por favor asegúrese de utilizar una cuenta de correo válida pues posteriormente la'
					. ' necesitará para activar su cuenta.',
				'filters' => array('StripTags', 'StringTrim'),
				'label' => 'Dirección de correo electrónico:',
				'maxlength' => 200,
				'required' => true,
				'validators' => array('EmailAddress', array('StringLength', true, array('min' => 1, 'max' => 200))),
			))

			->addElement('text', 'username', array(
				'class' => 'important',
				'description' => 'Utilice solamente letras y números',
				'filters' => array('StripTags', 'StringTrim'),
				'label' => 'Usuario:',
				'maxlength' => 100,
				'required' => true,
				'validators' => array('Alnum', array('StringLength', true, array('min' => 1, 'max' => 100))),
			))

			->addElement('password', 'password', array(
				'filters' => array('StripTags', 'StringTrim'),
				'label' => 'Contraseña / Confirme la contraseña:',
				'maxlength' => 100,
				'required' => true,
				'validators' => array(array('StringLength', true, array('min' => 1, 'max' => 100))),
			))

			->addElement('password', 'confirmPassword', array(
				'description' => 'Ambas contraseñas deben coincidir. Asegúrese de utilizar una contraseña diferente a'
					. ' la de su correo electrónico',
				'filters' => array('StripTags', 'StringTrim'),
				'maxlength' => 100,
				'required' => true,
				'validators' => array(array('StringLength', true, array('min' => 1, 'max' => 100))),
			))

			->addElement('text', 'firstname', array(
				'filters' => array('StripTags', 'StringTrim'),
				'label' => 'Nombres:',
				'maxlength' => 100,
				'required' => true,
				'style' => 'width:350px',
				'validators' => array(array('StringLength', true, array('min' => 2, 'max' => 100))),
			))

			->addElement('text', 'lastname', array(
				'filters' => array('StripTags', 'StringTrim'),
				'label' => 'Apellidos:',
				'maxlength' => 100,
				'required' => true,
				'style' => 'width:350px',
				'validators' => array(array('StringLength', true, array('min' => 2, 'max' => 100))),
			))

			->addElement('captcha', 'human', array(
				'label' => 'Ingrese el texto de la imágen:',
				'captcha' => array(
					'captcha' => 'image',
					'imgUrl' => BASE_URL . '/uploads/captcha',
					'imgDir' => BASE_PATH . '/uploads/captcha',
					'wordLen' => 4,
					'font' => LIBRARY_PATH . '/VendemeGratis/fonts/Vera.ttf',
				),
				'required' => true,
			))

			->addElement('select', 'country', array(
				'label' => 'País de residencia:',
				'multiOptions' => $countryOptions,
				'style' => 'width:350px',
			))

			->addElement('text', 'state', array(
				'filters' => array('StripTags', 'StringTrim'),
				'label' => 'Departamento o estado:',
				'maxlength' => 100,
				'style' => 'width:350px',
				'validators' => array(array('StringLength', true, array('min' => 0, 'max' => 100))),
			))

			->addElement('text', 'city', array(
				'filters' => array('StripTags', 'StringTrim'),
				'label' => 'Ciudad:',
				'maxlength' => 100,
				'style' => 'width:350px',
				'validators' => array(array('StringLength', true, array('min' => 0, 'max' => 100))),
			))

			->addElement('radio', 'gender', array(
				'label' => 'Género:',
				'maxlength' => 100,
				'multiOptions' => $genderOptions,
			))

			->addElement('text', 'birthDate', array(
				'class' => 'date',
				'label' => 'Fecha: de nacimiento',
				'maxlength' => 10,
				'validators' => array('Date'),
				'style' => 'width:7em',
			))

			->addElement('checkbox', 'accept', array(
				'label' => 'Acepto los términos y condiciones de uso de VendemeGratis.com',
				'required' => true,
				'validators' => array(array('Identical', false, array('token' => '1'))),
			))

			->addElement('button', 'submit', array(
				'label' => 'Registrarse',
				'ignore' => true,
				'type' => 'submit',
			))

			->addElement('button', 'cancel', array(
				'label' => 'Cancelar',
				'ignore' => true,
				'type' => 'button',
				'onclick' => 'history.go(-1)',
			))
			;

		$this->password
			->addDecorator('HtmlTag', array(
				'tag' => 'dd',
				'openOnly' => true,
				'placement' => Zend_Form_Decorator_Abstract::PREPEND,
			));
		$this->confirmPassword
			->removeDecorator('Label')
			->addDecorator('HtmlTag', array(
				'closeOnly' => true,
				'placement' => Zend_Form_Decorator_Abstract::APPEND,
				'tag' => 'dd',
			));

		$this->accept
			->removeDecorator('HtmlTag')
			->removeDecorator('Label')
			->removeDecorator('Errors')
			->addDecorator('Label', array(
				'placement' => Zend_Form_Decorator_Abstract::APPEND,
			))
			->addDecorator('Errors')
			->addDecorator('HtmlTag', array(
				'tag' => 'dd'
			))
			;

		$this->submit
			->removeDecorator('DtDdWrapper')
			->addDecorator('HtmlTag', array(
				'class' => 'buttons',
				'openOnly' => true,
				'placement' => Zend_Form_Decorator_Abstract::PREPEND,
				'tag' => 'dd',
			));

		$this->cancel
			->removeDecorator('DtDdWrapper')
			->addDecorator('HtmlTag', array(
				'closeOnly' => true,
				'placement' => Zend_Form_Decorator_Abstract::APPEND,
				'tag' => 'dd',
			));
	}
}

